package com.qf.controller;

import com.qf.dto.R;
import com.qf.entity.TAdminUser;
import com.qf.entity.TSmsTemplate;
import com.qf.mapper.UserMapper;
import com.qf.service.SmsTempService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/*
杨威
2021/10/29
20:58
*/
@RestController
@RequestMapping("/smstemps")
@Api("模板")
public class SmsTempController {
    private SmsTempService smsTempService;
    @Autowired
    public void setSmsTempService(SmsTempService smsTempService) {
        this.smsTempService = smsTempService;
    }

    @PostMapping("/temp")
    @ApiOperation("添加模板")
    public R addTemp(@RequestBody TSmsTemplate tSmsTemplate, HttpSession session){
        TAdminUser user = (TAdminUser)session.getAttribute("user");
        if(user!=null){
            Long id = user.getId();
            tSmsTemplate.setCreater(id);
            Long type = user.getType();
            tSmsTemplate.setOwntype(type);
        }
        smsTempService.addSmsTemp(tSmsTemplate);
        return R.setOk();
    }
    @GetMapping("/findByMultiParam")
    public R findByMultiParam(TSmsTemplate tSmsTemplate) throws Exception {
        List<TSmsTemplate> byMultiParam = smsTempService.findByMultiParam(tSmsTemplate);
        return R.setOk(byMultiParam);
    }
}
